<?php
                $resultStr;
                for($i=0;$i<=2;$i++)
              { 
                $f = new SaeFetchurl();     
                $day="&day=".$i;
                $url="http://php.weather.sina.com.cn/xml.php?city=%B9%E3%D6%DD&password=DJOYnieT8234jlsK".$day;
                $weather = $f->fetch($url);
                //用正则表达式获取数据
                preg_match_all( "/\<city\>(.*?)\<\/city\>/", $weather, $w_city);
                preg_match_all( "/\<status2\>(.*?)\<\/status2\>/", $weather, $w_status2);
                preg_match_all( "/\<status1\>(.*?)\<\/status1\>/", $weather, $w_status1);
                preg_match_all( "/\<temperature2\>(.*?)\<\/temperature2\>/", $weather, $w_temperature2);
                preg_match_all( "/\<temperature1\>(.*?)\<\/temperature1\>/", $weather, $w_temperature1);
                preg_match_all( "/\<chy_shuoming\>(.*?)\<\/chy_shuoming\>/", $weather, $w_chy_shuoming);
                preg_match_all( "/\<yd_s\>(.*?)\<\/yd_s\>/", $weather, $w_yds);    
                preg_match_all( "/\<savedate_weather\>(.*?)\<\/savedate_weather\>/", $weather, $w_savedate_weather);
                //如果天气变化一致
                if($w_status2==$w_status1)
                {
                        $w_status=$w_status2[1][0];
                }
                else
                {
                        $w_status=$w_status2[1][0]."转".$w_status1[1][0];
                }
                //将获取到的数据拼接起来
                $weather_res="西三天气预报".
                "\n发布时间：".$w_savedate_weather[1][0].
                "\n天气：".$w_status.
                "\n气温：".$w_temperature2[1][0]."-".$w_temperature1[1][0].
                "\n出行：".$w_yds[1][0].
                "\n穿衣：".$w_chy_shuoming[1][0]."\n\n\n\n";
                $resultStr.= $weather_res;
              }
              
           $resultStr.="天气消息来源于新浪天气\n回复【菜单】返回首页";
           $textTpl = "<xml>
            <ToUserName><![CDATA[%s]]></ToUserName>
            <FromUserName><![CDATA[%s]]></FromUserName>
            <CreateTime>".time()."</CreateTime>
            <MsgType><![CDATA[%s]]></MsgType>
            <Content><![CDATA[%s]]></Content>
            <FuncFlag>0</FuncFlag>
             </xml>";   
           $result = sprintf($textTpl, $fromUsername, $toUsername,"text", $resultStr);
           echo $result;
           exit;
           
           
          ?>